package com.atguigu.cloud.payment8001.controller;


import com.atguigu.cloud.common.entity.Payment;
import com.atguigu.cloud.common.vo.CommonResult;
import com.atguigu.cloud.payment8001.service.PaymentService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zsc
 * @since 2021-04-09
 */
@RestController
@RequestMapping("/payment")
public class PaymentController {

    @Value("${server.port}")
    private String ServerPort;
    @Resource
    PaymentService paymentService;



    @PostMapping("/create")
    public CommonResult create(@RequestBody Payment payment) {
        boolean isSaved = paymentService.save(payment);
        if (!isSaved)
            return CommonResult.error().data("ServerPort",ServerPort);
        return CommonResult.ok().data("id", payment.getId()).data("ServerPort",ServerPort);
    }

    @GetMapping("/get/{id}")
    public CommonResult get(@PathVariable String id) {
        Payment payment = paymentService.getById(id);
        if (payment == null)
            return CommonResult.error().data("ServerPort",ServerPort);
        return CommonResult.ok().data("payment", payment).data("ServerPort",ServerPort);
    }

}

